package cn.wlj.mq.routing;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName RoutingMqConfig
 * @Description TODO
 * @Author WLJ
 * @Date 2024/1/23 20:10
 * @Version 1.0
 */
@Configuration
public class RoutingMqConfig {
    // 交换机名称
    public static final String EXCHANGE_NAME = "routing_boot_exchange";

    // 队列名称1
    public static final String QUEUE_NAME1 = "routing_boot_queue1";
    // 队列名称2
    public static final String QUEUE_NAME2 = "routing_boot_queue2";
    // 队列名称3
    public static final String QUEUE_NAME3 = "routing_boot_queue3";

    // 路由键1
    public static final String ROUTING_KEY1 = "routing_boot_key1";
    // 路由键2
    public static final String ROUTING_KEY2 = "routing_boot_key2";

    // 声明队列
    @Bean
    public Queue routingBootQueue1() {
        return new Queue(QUEUE_NAME1);
    }
    @Bean
    public Queue routingBootQueue2() {
        return new Queue(QUEUE_NAME2);
    }
    @Bean
    public Queue routingBootQueue3() {
        return new Queue(QUEUE_NAME3);
    }

    // 声明交换机
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(EXCHANGE_NAME);
    }

    // 将队列绑定在交换机上，队列2和队列3绑定在同一个路由键上
    @Bean
    public Binding bindingRoutingExchange1(Queue routingBootQueue1, DirectExchange directExchange) {
        return BindingBuilder.bind(routingBootQueue1).to(directExchange).with(ROUTING_KEY1);
    }
    @Bean
    public Binding bindingRoutingExchange2(Queue routingBootQueue2, DirectExchange directExchange) {
        return BindingBuilder.bind(routingBootQueue2).to(directExchange).with(ROUTING_KEY2);
    }
    @Bean
    public Binding bindingRoutingExchange3(Queue routingBootQueue3, DirectExchange directExchange) {
        return BindingBuilder.bind(routingBootQueue3).to(directExchange).with(ROUTING_KEY2);
    }
}
